<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>静态资源管理</title>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
</head>
<!--/meta 作为公共模版分离出去-->

<body>
    <!--_header 作为公共模版分离出去-->
    <header class="navbar-wrapper" id="header">

    </header>
    <!--/_header 作为公共模版分离出去-->

    <!--_menu 作为公共模版分离出去-->
    <aside class="Hui-aside" id="menu">
    </aside>
    <div class="dislpayArrow hidden-xs"> <a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a>
    </div>
    <!--/_menu 作为公共模版分离出去-->

    <section class="Hui-article-box">
        <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="../index.html" class="maincolor">首页</a>
            <span class="c-gray en">&gt;</span>
            静态资源管理
            <span class="c-gray en">&gt;</span>
            <span id="mbx"></span>

            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
        </nav>
        <div class="Hui-article">
            <article class="cl pd-20">
                <div class="cl pd-5 bg-1 bk-gray">
                    <span class="l">
                        <a href="javascript:upload();" class="btn btn-primary radius">
                            <i class="Hui-iconfont">&#xe600;</i> 上传图片</a>
                    </span>
                    <span class="r">共有：
                        <strong id="counts"></strong> 个对象</span>
                </div>
                <table class="table table-border table-bordered table-bg">
                    <thead>
                        <tr class="text-c">
                            <th width="25%" background="../static/images/linebg.gif">
                                <strong>文件名</strong>
                            </th>
                            <th width="16%" background="../static/images/linebg.gif">
                                <strong>文件大小</strong>
                            </th>
                            <th width="22%" background="../static/images/linebg.gif">
                                <strong>最后修改时间</strong>
                            </th>
                            <th width="34%" background="../static/images/linebg.gif">
                                <strong>操作</strong>
                            </th>
                        </tr>
                    </thead>
                    <tbody id="list-table">
                        <tr class="text-c">
                            <td>
                                <a href="javascript:void(0);" id="Parent-directory">
                                    <img src="../static/images/dir2.gif" style="width: 16px; height: 16px;">
                                    上级目录</a></td>
                            <td>当前目录:
                                <span style="color:#f00;" id="activepath"> </span> 　</td>
                            <td></td>
                            <td></td>
                        </tr>
                    </tbody>
                </table>
            </article>
        </div>
    </section>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.page.js"></script>
    <!--/_footer /作为公共模版分离出去-->

    <script type="text/javascript" src="../static/js/admin.js?123"></script>
    <script type="text/javascript" src="../static/js/header.js?123"></script>
    <script type="text/javascript" src="../static/js/menu.js?1234"></script>

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="../lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="../lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="../lib/jquery.validation/1.14.0/messages_zh.js"></script>

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">
        var activepath = ""
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == "activepath") {
                activepath = pair[1];
            }
        }
        // console.log(activepath);
        $.ajax({
            type: 'post',
            url: '/ajax/file_manager/list',
            data: {
                "activepath": activepath
            },
            dataType: "json",
            beforeSend: function (request) {
                request.setRequestHeader("authStr", window.localStorage.getItem(
                    "userId") + "-" + window.localStorage.getItem("token"));
            },
            success: function (data) {
                console.log(data);
                var dList = data.data.dList;
                var fList = data.data.fList;
                var activepath = data.data.activepath;

                if (activepath!="" && activepath!="/") {  // 跟目录问配置中的静态资源目录
                    var pdir = activepath.substring(0,  activepath.lastIndexOf("/"));
                    $("#Parent-directory").attr("href", "list.html?activepath="+pdir);
                    $("#activepath").text(activepath);
                } else {
                    $("#activepath").text("/");
                }

                var counts = 0;
                var dir_str = "";
                for (let i = 0; i < dList.length; i++) {
                    const dirname = dList[i];
                    dir_str +=
                        '<tr class="text-c" style="height:26px; " onMouseMove="javascript:this.bgColor=\'#FCFDEE\';"onMouseOut="javascript:this.bgColor=\'#FFFFFF\';">';
                    dir_str += '<td class="text-l">';
                    dir_str += '<a href="list.html?activepath=' + (activepath + '/' + dirname) + '">';
                    dir_str += '<img src=../static/images/dir.gif style="width:16px; height:16px;" >' + dirname +
                        '</a>';
                    dir_str += '</td>';
                    dir_str += '<td>　</td>';
                    dir_str += '<td>　</td>';
                    dir_str += '<td><!--<a href="javascript:; " class="btn">改名</a>-->';
                    dir_str +=
                        '<a href="javascript:void(0);" class="btn" onclick="del(this, \'' + dirname + '\')">删除</a></td>';
                    dir_str += '</tr>';
                    counts++;
                }
                $("#list-table").append(dir_str);

                var file_str = "";
                for (let i = 0; i < fList.length; i++) {
                    const fileobj = fList[i];
                    file_str +=
                        '<tr class="text-c" style="height:26px; " onMouseMove="javascript:this.bgColor=\'#FCFDEE\'; "onMouseOut="javascript:this.bgColor=\'#FFFFFF\';">';
                    file_str += '<td class="text-l">';
                    file_str += '<a href="/data' + activepath + '/' + fileobj.fileName + '" title="新标签打开图片文件" target="_blank">';
                    file_str += '<img src=../static/images/'+fileobj.suffix+'.png style="width:16px; height:16px;" >' + fileobj.fileName + '</a>';
                    file_str += '</td>';
                    file_str += '<td>'+sizeBKM(fileobj.size)+'</td>';
                    file_str += '<td>'+formatDate(fileobj.time)+'</td>';
                    file_str += '<td><a href="javascript:void(0);" onclick=\'preview("'+fileobj.fileName+'")\' class="btn" title="预览图片">查看</a>&nbsp;';
                    file_str += '<!--<a href="javascript:; " class="btn">改名</a>&nbsp;-->';
                    file_str += '<a href="javascript:void(0);" class="btn" onclick="del(this, \''+fileobj.fileName+'\')">删除</a>&nbsp;';
                    file_str += '<!--<a href="" class="btn" >移动</a>--></td>';
                    file_str += '</tr>';
                    counts++;
                }
                $("#list-table").append(file_str);
                $("#counts").text(counts);
            }
        });

        /* 预览图片 */
        function preview(filename) {
            // console.log(filename);
            url = "view.html?activepath="+activepath+"&imgname="+filename;
            layer_show("查看图片",url,800,500);
        }

        /* 删除图片 or 目录 */
        function del(obj, filename) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'post',
                    url: '/ajax/file_manager/delete',
                    data: {
                        'activePath': activepath,
                        'fileName': filename
                    },
                    dataType: "json",
                    beforeSend: function (request) {
                        request.setRequestHeader("authStr", window.localStorage.getItem(
                            "userId") + "-" + window.localStorage.getItem("token"));
                    },
                    success: function (data) {
                        if (data.success == true) {
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 1000
                            });
                            $(obj).parents('tr').remove();
                        } else {
                            layer.msg(data.msg, {
                                icon: 5,
                                time: 1000
                            });
                            return false;
                        }
                    }
                });
            });
        }

        function upload() {
            url = "upload.html?activepath="+activepath;
            layer_show("查看图片",url,800,500);
        }
    </script>
    <!--请在上方写此页面业务相关的脚本-->
</body>

</html>